package com.zkyc.framework.website.mapper;

import com.alibaba.fastjson.JSONObject;
import com.zkyc.framework.common.vo.website.ClickRateVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author bing.bai,rxc
 */
@Mapper
public interface ClickRateMapper {

    @Select({"<script>" +
            "select  content_id,MAX(click_rate_total) as total_cLick from system_click_rate" +
            " GROUP BY content_id HAVING content_id in " +
            "    <foreach item='item' index='index' collection='contentIds' open='(' separator=',' close=')'>" +
            "       #{item}" +
            "    </foreach>" +
            "</script>"
    })
    List<ClickRateVo> getClickList(@Param("contentIds") List<Integer> contentIds);

    @Select("SELECT a.content_id,SUM(a.click_rate) as click_rate,b.content_title from system_click_rate a RIGHT JOIN web_content b on " +
            "a.content_id = b.id and b.status = 1 and b.website_id = #{websiteId} where  date_format(click_date,'%Y-%m-%d') < date_format(now(),'%Y-%m-%d') and " +
            "date_format(click_date,'%Y-%m-%d') >= date_format(date_sub(now(), interval 7 day),'%Y-%m-%d') GROUP BY" +
            " content_id ORDER BY click_rate desc limit 5")
    List<JSONObject> getTop5(Integer websiteId);

    @Select({"<script>" +
            "SELECT MAX(click_rate_total) AS total_cLick FROM system_click_rate " +
            "GROUP BY content_id HAVING content_id = #{contentId} " +
            "</script>"
    })
     Integer getClick(@Param("contentId") Integer contentId);
}
